import axios from 'axios'
import Cookies from 'js-cookie'

const http2 = axios.create({
	// baseUrl: 'http://8.134.217.48:8989/yuexinban',
	baseURL: 'http://127.0.0.1:8989/yuexinban',
		// baseUrl: "/api",
	// baseUrl: 'https://api.szlwyxb.com',
	headers: {
		"Content-Type": "application/json"
	},
	timeout: 30000
})

http2.webSite = 'http://127.0.0.1:8989/yuexinban/api'
// http2.webSite = 'http://8.134.217.48:8989/yuexinban/api'
// http2.webSite = 'https://api.szlwyxb.com'

http2.interceptors.request.use(config => {
	console.log(config)

	// 1.从缓存中获取到token,这里的Authorization时登录时你给用户设置token的键值
	let authorization = Cookies.get('token')
	// 2.如果token不为null，那么设置到请求头中，此处哪怕为null，我们也不进行处理，因为后台会进行拦截
	if (authorization) {
		//后台给登录用户设置的token的键时什么，headers['''']里的键也应该保持一致
		config.headers['Authorization'] = authorization
	}
	// 3.放行
	return config

	// return config
}, err => {
	return Promise.reject(err)
})
/**
 * 响应拦截
 */
http2.interceptors.response.use(res => {
	return res



}, err => {
	return Promise.reject(err)
})


export default http2